package com.qingke.zhu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Sqlconnect {
	public static Connection getConnection() throws SQLException{

	      String driver = "com.mysql.jdbc.Driver";
	      String url="jdbc:mysql://localhost:3306/player?useSSL=false";
	      String username = "root";
	      String password = "xyaychA153813";

	      try {
	          Class.forName(driver);
	      } catch (ClassNotFoundException e) {
	          throw new RuntimeException(e);
	      }

	      Connection conn = DriverManager.getConnection(url, username, password);
	      return conn;
	  }
	
	  public static void cleanup(Connection conn, Statement statement, ResultSet rs) {
	        if (rs != null) {
	            try {
	                rs.close();
	            } catch (SQLException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        if (statement != null) {
	            try {
	                statement.close();
	            } catch (SQLException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        if (conn != null) {
	            try {
	                conn.close();
	            } catch (SQLException e) {
	                throw new RuntimeException(e);
	            }
	        }
	    }
}
